﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace CashierSystem.DoctorRecordManager
{
    public partial class SearchOcRecordForm : Form
    {
        string customerId;
        public SearchOcRecordForm(string customerId)
        {
            this.customerId = customerId;
            InitializeComponent();
        }

        private void SearchOcRecordForm_Load(object sender, EventArgs e)
        {
            label1.Text = CashierInManager.CashierInManager.loadOneCustomerName(customerId);
            DoctorRecordManager.loadOneCusTreat(listView1, customerId);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count != 1)
            {
                DialogResult response = MessageBox.Show("请选择一条记录！");
                return;

            }
            else
            {
                DialogResult r = MessageBox.Show("请确认诊疗已完成", "请确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                if (r == System.Windows.Forms.DialogResult.Yes)
                {
                    string treatmentId = listView1.SelectedItems[0].SubItems[4].Text;
                    DoctorRecordManager.updateTreatment(treatmentId);
                    DoctorRecordManager.saveOneTreat(customerId, treatmentId);
                    DialogResult response = MessageBox.Show("诊疗已完成！");
                    DoctorRecordManager.loadOneCusTreat(listView1, customerId);
                }
                else
                {
                    return;
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string startDate = tbStartDate.Text;
            string endDate = tbEndDate.Text;
            DoctorRecordManager.searchCusTreat(listView1, customerId, startDate, endDate);
        }

        private void dtpStartDate_ValueChanged(object sender, EventArgs e)
        {
            tbStartDate.Text = dtpStartDate.Value.Date.ToString();
        }

        private void dtpEndDate_ValueChanged(object sender, EventArgs e)
        {
            tbEndDate.Text = dtpEndDate.Value.Date.ToString();
        }

    }
}